/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.EventDaoImpl;
import dao.UserDao;
import dao.UserDaoImpl;
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author takamflore
 */
public class DeleteEventServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;
    @EJB
    EventDaoImpl eventDao;
    @EJB
    UserDao user;        
    String forward="";
    
    public DeleteEventServlet() {
        super();
        eventDao = new EventDaoImpl();
        user= new UserDaoImpl();
    }

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
      
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String Events;
         String action = request.getParameter("action");
        int i= user.getUserId(request.getRemoteUser());
      
        if (action.equalsIgnoreCase("Delete")){
            int eventId = Integer.parseInt(request.getParameter("eventId"));
            eventDao.DeleteEvent(eventId);          
            request.setAttribute("Events", eventDao.getAllEvent(i));
            
        }else{
            request.setAttribute("Events", eventDao.getAllEvent(i));
        }
        forward ="WEB-INF/entity/event/List_Event.jsp";
        RequestDispatcher view = request.getRequestDispatcher(forward);
        view.forward(request, response);
    }
  
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int i= user.getUserId(request.getRemoteUser());
        request.setAttribute("Events", eventDao.getAllEvent(i));
         forward ="WEB-INF/entity/event/List_Event.jsp";
         RequestDispatcher view = request.getRequestDispatcher(forward);
        view.forward(request, response);
       
       
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
